package dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import dao.BaseDao;
import dao.regDao;

public class regDaoimpl extends BaseDao implements regDao {

	@Override
	public int reg(String name,String pwd) {
		String sql="SELECT loginName FROM `user` WHERE loginName=?";
		Object[] params={name};
		ResultSet rs=this.executeQuery(sql, params);
		try {
			if (rs.next()) {
				String loginName=rs.getString("loginName");
				if (loginName.equals(name)) {
					return 0;
				}
			}else {
				String sqlString="INSERT INTO `user`(loginName,`password`) VALUES (?,?)";
				Object[] paramsObjects={name,pwd};
				int r2=this.executeUpdate(sqlString, paramsObjects);
				return r2;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	
}
